<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../../css/app.css">
    <link rel="stylesheet" type="text/css" href="../comm/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/tabBar.css">
    <link rel="stylesheet" type="text/css" href="../comm/shop_comm.css" />
    <link rel="stylesheet" type="text/css" href="./css/dialog_fm.css">
    <title>推荐</title>
</head>

<body>
    <div id="app">
        <div class="dialog_fm_win" @click.stop>
            <div class="dialog_fm_head">
                推荐人邀请码
            </div>
            <div class="dialog_fm_inp">
                <input type="number" name="" v-model="code"  oninput="if(value.length>11)value=value.slice(0,11)" placeholder="请输入推荐人邀请码">
            </div>
            <div class="dialog_fm_btn">
                <span @click="sendCode">确定</span>
            </div>
        </div>
    </div>
</body>
<script src="../../sea.js" data-main="../../main"></script>
<script type="text/javascript" src="../../vue.js"></script>
<script type="text/javascript">
    apiready = function() {
        seajs.use(["../../api", "../../jquery", "../../app", "../../service", ], function($api, $, app, service) {
            var vm = {
                el: "#app",
                data: {
                    code: '',
                    offon:true
                },
                mounted: function() {
                  // this.getUserShopInfo()
                },
                methods: {
                    // 获取用户信息
                    getUserShopInfo: function(cb) {
                        app.ajax(
                            service['getUserShopInfo'], {
                                data: {
                                    values: {
                                        appid: app.appid,
                                        userid: $api.getStorage("user").data.out_user_id,
                                        mask: 'none',
                                        bs: ''
                                    }
                                }
                            },
                            function(res) {
                                if (res.code == 0) {
                                    $api.setStorage("shop_unionid", res.data.shop_unionid);
                                    $api.setStorage("shop_data", res.data);
                                    $api.setStorage("user", res);
                                    cb();
                                }
                            })
                    },
                    // 确定推荐人邀请码
                    sendCode: function() {
                      var that = this
                      if(this.offon){
                        this.offon = false
                        setTimeout(function(){
                          that.offon = true
                        },3000)
                        if (this.code.length == 0) {
                            api.toast({
                                msg: '请填写邀请码',
                                duration: 2000,
                                location: 'bottom'
                            });
                        } else {
                            app.ajax(service.checkInvitationCode, {
                                data: {
                                    values: {
                                        invite_code: this.code,
                                        unionid: $api.getStorage("shop_unionid"),
                                        mask:'none'
                                    }
                                }
                            }, function(res) {
                                if (res.code == 0) {
                                    that.getUserShopInfo(function(){
                                      if($api.getStorage('user').data.higher.length==0){
                                        api.toast({
                                            msg: '绑定推荐人失败...',
                                            duration: 2000,
                                            location: 'bottom'
                                        });
                                      }else{
                                        api.sendEvent({
                                            name: 'Openshop_fm'
                                        });
                                        api.sendEvent({
                                            name: 'memberINIT'
                                        });
                                        api.closeFrame();
                                      }
                                    })
                                }
                            })
                        }
                      }
                    }
                }
            }
            var even = function() {}
            var newVue = new Vue(vm);
            even();
        })
    }
</script>

</html>
